from tasks.models import TaskExecutionLog
import sys

# 获取最新的5条任务执行日志
print("获取最新的5条任务执行日志...")
logs = TaskExecutionLog.objects.all().order_by('-start_time')[:5]
print(f"找到{len(logs)}条日志记录\n")

for log in logs:
    print(f"日志ID: {log.id}")
    print(f"开始时间: {log.start_time}")
    print(f"结束时间: {log.end_time}")
    print(f"执行成功: {log.is_success}")
    print(f"处理总数: {log.total_processed}")
    print(f"成功数量: {log.success_count}")
    print(f"失败数量: {log.failure_count}")
    
    # 显示部分日志内容
    if log.log_content:
        preview = log.log_content[:200] + "..." if len(log.log_content) > 200 else log.log_content
        print(f"日志内容预览: {preview}")
    
    if log.error_message:
        print(f"错误信息: {log.error_message}")
    
    print("="*50)